package com.by.controller;

import com.by.bean.ShopCategory;
import com.by.common.core.bean.ResultBean;
import com.by.common.core.controller.BaseController;
import com.by.service.ShopCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

@RestController
@RequestMapping("/shopCategory")
@Api(tags = "店铺分类")
public class ShopCategoryController extends BaseController {
    @Autowired
    ShopCategoryService service;

    @PostMapping("/saveone")
    @ApiOperation("新增一级分类")
    public ResultBean saveFirstCategory(ShopCategory shopCategory){
        int i = service.saveSCategoryOne(shopCategory);
        return saveResult(i);
    }
    @PostMapping("/savekid")
    @ApiOperation("新增子分类")
    public ResultBean saveSecondCategory(ShopCategory shopCategory){
        int i = service.saveSCategoryKids(shopCategory);
        return saveResult(i);
    }
    @GetMapping("/tree")
    @ApiOperation("类别树")
    public ResultBean CategoryTee(){
        List<ShopCategory> shopCategories = service.categoryTree();
        return success("成功",shopCategories);
    }
    @PutMapping("/update")
    @ApiOperation("修改类别")
    public ResultBean updateShopCategory( int id,  String name){
        int i = service.updateSname(id, name);
        return updateResult(i);
    }
    @DeleteMapping("/delete")
    @ApiOperation("删除类别")
    public ResultBean deleteSCategory(int id){
        int n= service.deleteShop(id);
        return deleteResult(n);
    }
}
